const { Sdk_Platform, WX_AD_CONFIG } = require("../../frame/constants");

cc.Class({
    extends: cc.Component,

    properties: {
        bottom_node: cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {

    },

    // update (dt) {},

    initPage() {
        if (!he.pool.getPool('adIcon')) {
            he.pool.createPoolSync('adIcon', 10, cc.Prefab, 'uimod/adIcon')
        }
        if (!he.pool.getPool('adIconSec')) {
            he.pool.createPoolSync('adIconSec', 5, cc.Prefab, 'uimod/adIconSec')
        }
    },

    updatePage(param) {
        this.adSwitch(true)
        this.bottom_node.active = false
        gg.eventManager.on('bottomAdCtl', this.stateAd, this)
    },

    closeUI() {
        gg.eventManager.off('bottomAdCtl', this.stateAd, this)
    },

    adSwitch(status) {
        if (status) {
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    if (!common.showAd) return
                    he.ad.getTdAdJson(WX_AD_CONFIG.tmIcon[11], this.bottomSet.bind(this))
                    break
            }
        } else {
            //  关掉广告
        }
    },

    bottomSet(config) {
        console.log(config)
        let pre = he.pool.getElement('scrollAd')
        pre.parent = this.bottom_node
        pre.getComponent('scrollAd').init(config.creatives)
    },
    //广告控制
    stateAd(state) {
        if (state == 1) {
            this.bottom_node.active = true
        } else if (state == 0) {
            this.bottom_node.active = false
        } else {
            this.uiBase.closePage()
        }
    },
});
